﻿Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Drawing
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Public Class HitTestInfo
        ' Methods
        Friend Sub New()
        End Sub

        Public Sub New(ByVal designer As ActivityDesigner, ByVal location As HitTestLocations)
            If (designer Is Nothing) Then
                Throw New ArgumentNullException("designer")
            End If
            Me.activityDesigner = designer
            Me.location = location
        End Sub

        Public Overridable Function MapToIndex() As Integer
            Dim activity As CompositeActivity = [TryCast](Me.activityDesigner.Activity,CompositeActivity)
            If (Not activity Is Nothing) Then
                Return activity.Activities.Count
            End If
            Return 0
        End Function


        ' Properties
        <Browsable(False)> _
        Public ReadOnly Property AssociatedDesigner As ActivityDesigner
            Get
                Return Me.activityDesigner
            End Get
        End Property

        <Browsable(False)> _
        Public Overridable ReadOnly Property Bounds As Rectangle
            Get
                If (Not Me.activityDesigner Is Nothing) Then
                    Return Me.activityDesigner.Bounds
                End If
                Return Rectangle.Empty
            End Get
        End Property

        <Browsable(False)> _
        Public ReadOnly Property HitLocation As HitTestLocations
            Get
                Return Me.location
            End Get
        End Property

        Public Shared ReadOnly Property Nowhere As HitTestInfo
            Get
                If (HitTestInfo.nowhere Is Nothing) Then
                    HitTestInfo.nowhere = New HitTestInfo
                End If
                Return HitTestInfo.nowhere
            End Get
        End Property

        <Browsable(False)> _
        Public Overridable ReadOnly Property SelectableObject As Object
            Get
                If (Not Me.activityDesigner Is Nothing) Then
                    Return Me.activityDesigner.Activity
                End If
                Return Nothing
            End Get
        End Property

        <Browsable(False)> _
        Public ReadOnly Property UserData As IDictionary
            Get
                If (Me.userData Is Nothing) Then
                    Me.userData = New HybridDictionary
                End If
                Return Me.userData
            End Get
        End Property


        ' Fields
        Private activityDesigner As ActivityDesigner
        Private location As HitTestLocations
        Private Shared nowhere As HitTestInfo
        Private userData As IDictionary
    End Class
End Namespace

